/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.isn.historiaclinica.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlTransient;

import com.isn.atencionemergencia.entity.OrdenDeAtencionDeEmergencia;
import com.isn.atencionemergencia.entity.ResultadoDeOrdenDeAtencionDeEmergencia;
import com.isn.logueo.entity.Usuario;

/**
 *
 * @author pool
 */
@Entity
@Table(name = "historia_clinica")
@NamedQueries({
    @NamedQuery(name = "HistoriaClinica.findAll", query = "SELECT h FROM HistoriaClinica h"),
    @NamedQuery(name = "HistoriaClinica.find", query = "SELECT h FROM HistoriaClinica h WHERE h.numHc = :numHc or h.nomPac = :nomPac or h.apePatPac = :apePatPac or h.apeMatPac = :apeMatPac"),
    @NamedQuery(name = "HistoriaClinica.findByNumHc", query = "SELECT h FROM HistoriaClinica h WHERE h.numHc = :numHc"),
    @NamedQuery(name = "HistoriaClinica.findByNomPac", query = "SELECT h FROM HistoriaClinica h WHERE h.nomPac = :nomPac"),
    @NamedQuery(name = "HistoriaClinica.findByApePatPac", query = "SELECT h FROM HistoriaClinica h WHERE h.apePatPac = :apePatPac"),
    @NamedQuery(name = "HistoriaClinica.findByApeMatPac", query = "SELECT h FROM HistoriaClinica h WHERE h.apeMatPac = :apeMatPac"),
    @NamedQuery(name = "HistoriaClinica.findBySexoPac", query = "SELECT h FROM HistoriaClinica h WHERE h.sexoPac = :sexoPac"),
    @NamedQuery(name = "HistoriaClinica.findByTeflPac", query = "SELECT h FROM HistoriaClinica h WHERE h.teflPac = :teflPac"),
    @NamedQuery(name = "HistoriaClinica.findByDirPac", query = "SELECT h FROM HistoriaClinica h WHERE h.dirPac = :dirPac"),
    @NamedQuery(name = "HistoriaClinica.findByFecNacPac", query = "SELECT h FROM HistoriaClinica h WHERE h.fecNacPac = :fecNacPac"),
    @NamedQuery(name = "HistoriaClinica.findByNumDoc", query = "SELECT h FROM HistoriaClinica h WHERE h.numDoc = :numDoc"),
    @NamedQuery(name = "HistoriaClinica.findByEstadoHc", query = "SELECT h FROM HistoriaClinica h WHERE h.estadoHc = :estadoHc"),
    @NamedQuery(name = "HistoriaClinica.findByFecReg", query = "SELECT h FROM HistoriaClinica h WHERE h.fecReg = :fecReg"),
    @NamedQuery(name = "HistoriaClinica.findByTipOpe", query = "SELECT h FROM HistoriaClinica h WHERE h.tipOpe = :tipOpe")})

public class HistoriaClinica implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "Num_Hc", columnDefinition="CHAR(5) unsigned")
    private String numHc;
    @Column(name = "Nom_Pac")
    private String nomPac;
    @Column(name = "Ape_Pat_Pac")
    private String apePatPac;
    @Column(name = "Ape_Mat_Pac")
    private String apeMatPac;
    @Column(name = "Sexo_Pac")
    private String sexoPac;
    @Column(name = "Tefl_Pac")
    private String teflPac;
    @Column(name = "Dir_Pac")
    private String dirPac;
    @Column(name = "Fec_Nac_Pac")
    @Temporal(TemporalType.DATE)
    private Date fecNacPac;
    @Column(name = "Num_Doc")
    private String numDoc;
    @Column(name = "Estado_Hc")
    private String estadoHc;
    @Basic(optional = false)
    @Column(name = "Fec_Reg")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecReg;
    @Basic(optional = false)
    @Column(name = "tip_ope")
    private String tipOpe;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "numHc")
    private Collection<OrdenDeAtencionDeEmergencia> ordenDeAtencionDeEmergenciaCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "numHc")
    private Collection<ResultadoDeOrdenDeAtencionDeEmergencia> resultadoDeOrdenDeAtencionDeEmergenciaCollection;
    @JoinColumn(name = "Usuario", referencedColumnName = "Usuario")
    @ManyToOne(optional = false)
    private Usuario usuario;
    @JoinColumn(name = "Cod_Tipdocu", referencedColumnName = "Cod_Tipdocu")
    @ManyToOne(optional = false)
    private TipoDeDocumento codTipdocu;
    @JoinColumns({
        @JoinColumn(name = "Cod_Prov", referencedColumnName = "Cod_Prov", insertable = false, updatable = false),
        @JoinColumn(name = "Cod_Depa", referencedColumnName = "Cod_Depa", insertable = false, updatable = false),
        @JoinColumn(name = "Cod_Distri", referencedColumnName = "Cod_Distri", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Distrito codDistri;
    /*
    @JoinColumn(name = "Cod_Depa", referencedColumnName = "Cod_Depa")
    @ManyToOne(optional = false)
    private Departamento codDepa;
    @JoinColumn(name = "Cod_Prov", referencedColumnName = "Cod_Prov")
    @ManyToOne(optional = false)
    private Provincia codProv;
*/
    public HistoriaClinica() {
    }

    public HistoriaClinica(String numHc) {
        this.numHc = numHc;
    }

    public HistoriaClinica(String numHc, Date fecReg, String tipOpe) {
        this.numHc = numHc;
        this.fecReg = fecReg;
        this.tipOpe = tipOpe;
    }

    public String getNumHc() {
        return numHc;
    }

    public void setNumHc(String numHc) {
        this.numHc = numHc;
    }

    public String getNomPac() {
        return nomPac;
    }

    public void setNomPac(String nomPac) {
        this.nomPac = nomPac;
    }

    public String getApePatPac() {
        return apePatPac;
    }

    public void setApePatPac(String apePatPac) {
        this.apePatPac = apePatPac;
    }

    public String getApeMatPac() {
        return apeMatPac;
    }

    public void setApeMatPac(String apeMatPac) {
        this.apeMatPac = apeMatPac;
    }

    public String getSexoPac() {
        return sexoPac;
    }

    public void setSexoPac(String sexoPac) {
        this.sexoPac = sexoPac;
    }

    public String getTeflPac() {
        return teflPac;
    }

    public void setTeflPac(String teflPac) {
        this.teflPac = teflPac;
    }

    public String getDirPac() {
        return dirPac;
    }

    public void setDirPac(String dirPac) {
        this.dirPac = dirPac;
    }

    public Date getFecNacPac() {
        return fecNacPac;
    }

    public void setFecNacPac(Date fecNacPac) {
        this.fecNacPac = fecNacPac;
    }

    public String getNumDoc() {
        return numDoc;
    }

    public void setNumDoc(String numDoc) {
        this.numDoc = numDoc;
    }

    public String getEstadoHc() {
        return estadoHc;
    }

    public void setEstadoHc(String estadoHc) {
        this.estadoHc = estadoHc;
    }

    public Date getFecReg() {
        return fecReg;
    }

    public void setFecReg(Date fecReg) {
        this.fecReg = fecReg;
    }

    public String getTipOpe() {
        return tipOpe;
    }

    public void setTipOpe(String tipOpe) {
        this.tipOpe = tipOpe;
    }

    @XmlTransient
    public Collection<OrdenDeAtencionDeEmergencia> getOrdenDeAtencionDeEmergenciaCollection() {
        return ordenDeAtencionDeEmergenciaCollection;
    }

    public void setOrdenDeAtencionDeEmergenciaCollection(Collection<OrdenDeAtencionDeEmergencia> ordenDeAtencionDeEmergenciaCollection) {
        this.ordenDeAtencionDeEmergenciaCollection = ordenDeAtencionDeEmergenciaCollection;
    }

    @XmlTransient
    public Collection<ResultadoDeOrdenDeAtencionDeEmergencia> getResultadoDeOrdenDeAtencionDeEmergenciaCollection() {
        return resultadoDeOrdenDeAtencionDeEmergenciaCollection;
    }

    public void setResultadoDeOrdenDeAtencionDeEmergenciaCollection(Collection<ResultadoDeOrdenDeAtencionDeEmergencia> resultadoDeOrdenDeAtencionDeEmergenciaCollection) {
        this.resultadoDeOrdenDeAtencionDeEmergenciaCollection = resultadoDeOrdenDeAtencionDeEmergenciaCollection;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public TipoDeDocumento getCodTipdocu() {
        return codTipdocu;
    }

    public void setCodTipdocu(TipoDeDocumento codTipdocu) {
        this.codTipdocu = codTipdocu;
    }

    public Distrito getCodDistri() {
        return codDistri;
    }

    public void setCodDistri(Distrito codDistri) {
        this.codDistri = codDistri;
    }
/*
    public Departamento getCodDepa() {
        return codDepa;
    }

    public void setCodDepa(Departamento codDepa) {
        this.codDepa = codDepa;
    }

    public Provincia getCodProv() {
        return codProv;
    }

    public void setCodProv(Provincia codProv) {
        this.codProv = codProv;
    }
*/
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (numHc != null ? numHc.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof HistoriaClinica)) {
            return false;
        }
        HistoriaClinica other = (HistoriaClinica) object;
        if ((this.numHc == null && other.numHc != null) || (this.numHc != null && !this.numHc.equals(other.numHc))) {
            return false;
        }
        return true;
    }
    
}
